package com.chixing.controller;


import com.chixing.service.IJobService;
import com.chixing.service.impl.JobServiceImpl;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-09-17
 */
@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
      private IJobService iJobService;

    @GetMapping("{id}")
    public Result getById(@PathVariable("id") Integer id){
        return  iJobService.getById(id);
    }

    @GetMapping("/search/jobTitle/{jobTitle}/jobSalaryMin/{jobSalaryMin}/jobSalaryMax/{jobSalaryMax}/experienceRequired/{experienceRequired}/jobLocation/{jobLocation}/educationRequired/{educationRequired}/employmentType/{employmentType}")
    public Result getByConditions(@PathVariable("jobTitle") String jobTitle,
                                  @PathVariable("jobSalaryMin") Double jobSalaryMin,
                                  @PathVariable("jobSalaryMax")  Double jobSalaryMax,
                                  @PathVariable("experienceRequired") String experienceRequired,
                                  @PathVariable("jobLocation")  String jobLocation,
                                  @PathVariable("educationRequired")  String educationRequired,
                                  @PathVariable("employmentType")  String employmentType ){
        return iJobService.getByConditions(jobTitle, jobSalaryMin, jobSalaryMax, experienceRequired, jobLocation, educationRequired, employmentType);
    }

    @GetMapping("/searchAll")
    public Result getAll(){
        return iJobService.getAll();
    }
    @GetMapping("/searchComJob")
    public Result getComJob(){
        return iJobService.getComJob();
    }

    //http://localhost:8080/app/job/name/java/min/15000.00/max/25000.00/year/3-5/city/%E5%8C%97%E4%BA%AC/degree/Bachelor/type/Full-time
    @GetMapping("name/{jobName}/min/{minSalary}/max/{maxSalary}/year/{workYear}/city/{city}/degree/{degree}/type/{employeeType}")
    public Result getConditions(@PathVariable("jobName") String jobName,
                                  @PathVariable("minSalary")Float minJobSalary,
                                  @PathVariable("maxSalary")Float maxJobSalary,
                                  @PathVariable("workYear")String workYear,
                                  @PathVariable("city")String jobCity,
                                  @PathVariable("degree")String degree,
                                  @PathVariable("employeeType")String employeeType) {
        return iJobService.getConditions(jobName, minJobSalary, maxJobSalary, workYear, jobCity, degree, employeeType);
    }

    //http://localhost:8080/app/job/search2?jobName=师
    //http://localhost:8080/app/job/search2?jobName=师&city=北京
    @GetMapping("/search2")
    public Result getConditions2(@RequestParam(value = "jobName",required = false) String jobName,
                                 @RequestParam(value = "minSalary",required = false)Float minJobSalary,
                                 @RequestParam(value = "maxSalary",required = false)Float maxJobSalary,
                                 @RequestParam(value = "workYear",required = false)String workYear,
                                 @RequestParam(value = "city",required = false)String jobCity,
                                 @RequestParam(value = "degree",required = false)String degree,
                                 @RequestParam(value = "employeeType",required = false)String employeeType) {
        return iJobService.getConditions(jobName, minJobSalary, maxJobSalary, workYear, jobCity, degree, employeeType);
    }

}
